package com.guodefu.unifiedresponse.exception;


import com.guodefu.unifiedresponse.IResult;

import java.io.Serial;

/**
 * 业务异常抽象基类
 *
 * @author guodefu909
 **/
public abstract class BaseException extends RuntimeException {

    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * transient变量不被序列化
     */
    private final transient IResult resultCode;

    /**
     * IResult.getMessage() 得到的消息，可能是消息模板，此时真正的消息存在此处 message 中
     */
    private final transient String message;

    public BaseException(IResult resultCode, String message) {
        super(resultCode.getMessage());
        this.resultCode = resultCode;
        this.message = message;
    }

    public BaseException(IResult resultCode, String message, Throwable cause) {
        super(cause);
        this.resultCode = resultCode;
        this.message = message;
    }

    public IResult getResultCode() {
        return resultCode;
    }

    public String getMessage() {
        return message;
    }
}